
#include "prog_io_debug.h"

/**
 * can-ctrl
 * Program: prog_io_debug
 */

int8_t prog_io_debug_init(void)
{
	register_slot(prog_io_debug_buttonpressed, btn_event);
	register_slot(prog_io_debug_potchange,pot_event);
	lcd_clear_display();
	lcd_clear_command_line();
	print_io_info();
	return 0;
}
int8_t prog_io_debug_uninit(void)
{
	unregister_slot(prog_io_debug_buttonpressed, btn_event);
	unregister_slot(prog_io_debug_potchange,pot_event);
	lcd_clear_display();
	lcd_clear_command_line();
	return 0;
}
int8_t prog_io_debug_run(void)
{
	print_io_info();
	return 1;
}

void prog_io_debug_buttonpressed(Event *ev)
{

	Button *in_data = (Button *) ev->data;
	uint16_t *time = (uint16_t *) ev->data+1;
	if(*in_data == joy_up)
		sound(8000,1200);
	if(*in_data == joy_left && *time > 5000)
		sound(3000,500);
	else
		sound(500,200);
	

}

void prog_io_debug_potchange(Event *ev)
{
	Potentiometer *pot = (Potentiometer *) ev->data;
	uint8_t *value = (uint8_t *) (ev->data +1);
	
 	if(*pot == pota)
		sound(*value * 20, 1000);

}